<!--
 * @Desc:
 * @author cheegon
 * @date 2024/06/28  上午9:54
-->
<template>
  <el-dialog class="publish_dialog" title="修改文章分类" :visible.sync="isShowPop">
    <el-form style="text-align: left" ref="formRef" :model="formData" :rules="formRules"
             class="edit_type_form">
      <el-form-item label="文章分类" prop="type">
        <el-select v-model="formData.typeId" placeholder="请选择文章分类" style="margin-right: 10px">
          <el-option v-for="item in list" :label="item.name" :value="item.id"></el-option>
        </el-select>
        <el-button @click="go2TypeManage">管理分类</el-button>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="handleSubmit">提交修改</el-button>
    </div>
  </el-dialog>
</template>

<script>
import dialogMixin from '@/mixins/dialogMixin'
import { reqAllTypeList, reqEditBlog } from '@/api/adminApi'

export default {
  name: "AEditBlogTypeDialog",
  components: {},
  props: [],
  mixins: [dialogMixin],
  data() {
    return {
      list: [],
      formData: {
        typeId: null
      },
      formRules: {
        typeId: [
          { required: true, message: '请选择类型', trigger: 'blur' }
        ],
      },
    }
  },
  created() {
  },
  methods: {
    refresh() {
      this.formData = {
        typeId: this.info.typeId
      }
      this.getList()
    },
    // 得到所有的分类
    getList() {
      reqAllTypeList().then(data => {
        this.list = data
      })
    },
    handleSubmit() {
      this.$refs.formRef.validate(async valid => {
        if (!valid) return;
        reqEditBlog({ id: this.info.id, typeId: this.formData.typeId }).then(data => {
          this.$message.success('修改博客分类成功！')
          this.isShowPop = false
          this.onComplete()
        })
      })
    },
    go2TypeManage(){
      this.$router.push('/admin/types')
    }
  }
}
</script>

<style lang="stylus" scoped>

</style>
